/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainForm.java
 *
 * Created on Nov 3, 2011, 6:05:32 PM
 */
package utama;

import Buku.FormPencatatanBukuBaru;
import Entity.Librarian;
import Laporan.FormMenuLaporan;
import Member.FormPencatatanMemberBaru;
import Pinjam_Kembali.FormPencatatanPeminjaman;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author evan_utomo
 */
public class MainForm extends javax.swing.JFrame {

    /** Creates new form MainForm */
    public MainForm() {
        initComponents();
        this.setResizable(false);

        this.jMenuBar1.setVisible(false);
        this.librarian = new Librarian();
        this.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent we) {
                logoutMenuItemActionPerformed(null);
                System.exit(0);
            }
        });
        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent we) {
                logoutMenuItemActionPerformed(null);
                System.exit(0);
            }
        });

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        formPencatatanPeminjaman = new Pinjam_Kembali.FormPencatatanPeminjaman();
        formPencatatanMemberBaru = new Member.FormPencatatanMemberBaru();
        formPencatatanBukuBaru = new Buku.FormPencatatanBukuBaru();
        formMenuLaporan = new Laporan.FormMenuLaporan();
        formUpdate = new Buku.FormUpdate();
        awalPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        loginButton = new java.awt.Button();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        pinjamMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        laporanMenuItem = new javax.swing.JMenuItem();
        logoutMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        memberBaruMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        bukuBaruMenuItem = new javax.swing.JMenuItem();
        updateMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        awalPanel.setBackground(new java.awt.Color(102, 102, 255));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Gambar/Great_Books.jpg"))); // NOI18N
        jLabel1.setText("jLabel1");

        loginButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        loginButton.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N
        loginButton.setLabel("Login");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Gambar/Great_Books.jpg"))); // NOI18N
        jLabel2.setText("jLabel2");

        javax.swing.GroupLayout awalPanelLayout = new javax.swing.GroupLayout(awalPanel);
        awalPanel.setLayout(awalPanelLayout);
        awalPanelLayout.setHorizontalGroup(
            awalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(awalPanelLayout.createSequentialGroup()
                .addGroup(awalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(awalPanelLayout.createSequentialGroup()
                        .addGap(208, 208, 208)
                        .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 561, Short.MAX_VALUE)
                    .addComponent(jLabel2, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        awalPanelLayout.setVerticalGroup(
            awalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, awalPanelLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        fileMenu.setText("Pinjam-Kembali");

        pinjamMenuItem.setText("Pinjam-Kembali");
        pinjamMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pinjamMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(pinjamMenuItem);
        fileMenu.add(jSeparator1);

        laporanMenuItem.setText("Laporan");
        laporanMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                laporanMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(laporanMenuItem);

        logoutMenuItem.setText("logout");
        logoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(logoutMenuItem);

        jMenuBar1.add(fileMenu);

        jMenu2.setText("Member");

        memberBaruMenuItem.setText("Member Baru");
        memberBaruMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memberBaruMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(memberBaruMenuItem);

        jMenuBar1.add(jMenu2);

        jMenu1.setText("Buku");

        bukuBaruMenuItem.setText("Buku Baru");
        bukuBaruMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bukuBaruMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(bukuBaruMenuItem);

        updateMenuItem.setText("Update");
        updateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(updateMenuItem);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(awalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(awalPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-566)/2, (screenSize.height-412)/2, 566, 412);
    }// </editor-fold>//GEN-END:initComponents

private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
    new LoginForm(this, true).setVisible(true);
    if (librarian.isStatus()) {
        this.jMenuBar1.setVisible(true);
        this.getContentPane().remove(this.awalPanel);

        this.getContentPane().setVisible(false);
        this.getContentPane().setVisible(true);
    }
}//GEN-LAST:event_loginButtonActionPerformed

private void pinjamMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pinjamMenuItemActionPerformed
    this.getContentPane().removeAll();
    this.getContentPane().setLayout(new BorderLayout());
    this.formPencatatanPeminjaman = new FormPencatatanPeminjaman();
    this.getContentPane().add(this.formPencatatanPeminjaman, BorderLayout.CENTER);
    int height = this.formPencatatanPeminjaman.getPreferredSize().height + 53;
    int width = this.formPencatatanPeminjaman.getPreferredSize().width;
    this.setSize(width, height);
    this.getContentPane().setVisible(false);
    this.getContentPane().setVisible(true);
}//GEN-LAST:event_pinjamMenuItemActionPerformed

private void memberBaruMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memberBaruMenuItemActionPerformed
    this.getContentPane().removeAll();
    this.getContentPane().setLayout(new BorderLayout());
    this.formPencatatanMemberBaru = new FormPencatatanMemberBaru();
    this.getContentPane().add(this.formPencatatanMemberBaru, BorderLayout.CENTER);
    int height = this.formPencatatanMemberBaru.getPreferredSize().height + 53;
    int width = this.formPencatatanMemberBaru.getPreferredSize().width;
    this.setSize(width, height);
    this.getContentPane().setVisible(false);
    this.getContentPane().setVisible(true);
}//GEN-LAST:event_memberBaruMenuItemActionPerformed

private void laporanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_laporanMenuItemActionPerformed
    this.formMenuLaporan = new FormMenuLaporan();
    this.getContentPane().removeAll();
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(this.formMenuLaporan, BorderLayout.CENTER);
    int height = this.formMenuLaporan.getPreferredSize().height + 53;
    int width = this.formMenuLaporan.getPreferredSize().width;
    this.setSize(width, height);
    this.getContentPane().setVisible(false);
    this.getContentPane().setVisible(true);
}//GEN-LAST:event_laporanMenuItemActionPerformed

private void logoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutMenuItemActionPerformed
    try {
        this.librarian.logout();
        this.librarian.setStatus(false);
        this.librarian.setUserName(null);
        this.librarian.setPassword(null);
        this.jMenuBar1.setVisible(false);
        this.getContentPane().removeAll();
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(this.awalPanel, BorderLayout.CENTER);
        int height = this.awalPanel.getPreferredSize().height + 53;
        int width = this.awalPanel.getPreferredSize().width;
        this.setSize(width, height);
        this.getContentPane().setVisible(false);
        this.getContentPane().setVisible(true);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }
}//GEN-LAST:event_logoutMenuItemActionPerformed

private void bukuBaruMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bukuBaruMenuItemActionPerformed
    this.getContentPane().removeAll();
    this.getContentPane().setLayout(new BorderLayout());
    this.formPencatatanBukuBaru = new FormPencatatanBukuBaru();
    this.getContentPane().add(this.formPencatatanBukuBaru, BorderLayout.CENTER);
    int height = this.formPencatatanBukuBaru.getPreferredSize().height + 53;
    int width = this.formPencatatanBukuBaru.getPreferredSize().width;
    this.setSize(width, height);
    this.getContentPane().setVisible(false);
    this.getContentPane().setVisible(true);
}//GEN-LAST:event_bukuBaruMenuItemActionPerformed

private void updateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMenuItemActionPerformed
    this.getContentPane().removeAll();
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(this.formUpdate, BorderLayout.CENTER);
    int height = this.formUpdate.getPreferredSize().height + 53;
    int width = this.formUpdate.getPreferredSize().width;
    this.setSize(width, height);
    this.getContentPane().setVisible(false);
    this.getContentPane().setVisible(true);
}//GEN-LAST:event_updateMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new MainForm().setVisible(true);
    }
    private Librarian librarian;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel awalPanel;
    private javax.swing.JMenuItem bukuBaruMenuItem;
    private javax.swing.JMenu fileMenu;
    private Laporan.FormMenuLaporan formMenuLaporan;
    private Buku.FormPencatatanBukuBaru formPencatatanBukuBaru;
    private Member.FormPencatatanMemberBaru formPencatatanMemberBaru;
    private Pinjam_Kembali.FormPencatatanPeminjaman formPencatatanPeminjaman;
    private Buku.FormUpdate formUpdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuItem laporanMenuItem;
    private java.awt.Button loginButton;
    private javax.swing.JMenuItem logoutMenuItem;
    private javax.swing.JMenuItem memberBaruMenuItem;
    private javax.swing.JMenuItem pinjamMenuItem;
    private javax.swing.JMenuItem updateMenuItem;
    // End of variables declaration//GEN-END:variables

    /**
     * @param librarian the librarian to set
     */
    public void setLibrarian(Librarian librarian) {
        this.librarian = librarian;
    }
}
